package com.xyh.transaction.excel;


import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ReadConverterContext;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.metadata.data.WriteCellData;

public class StatusConverter implements Converter<Integer> {


    @Override
    public WriteCellData<?> convertToExcelData(WriteConverterContext<Integer> context) throws Exception {
        Integer value = context.getValue();

        String status = "";

        if (value == null){
            return new WriteCellData<>(status);
        }

        if (value.equals(0)) {
            status = "禁用";
        } else {
            status = "启用";
        }

        return new WriteCellData<>(status);

    }


    @Override
    public Integer convertToJavaData(ReadConverterContext<?> context) throws Exception {
        String value = context.getReadCellData().getStringValue();

        if ("禁用".equals(value)) {
            return 0;
        }
        return 1;
    }
}
